//
//  ViewController.swift
//  ChineseZodiac
//
//  Created by lewis on 15/12/20.
//  Copyright © 2015年 lewis. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var yearOfBirth: UITextField!

    @IBOutlet weak var zodiacImg: UIImageView!

    let offset = 3;

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        yearOfBirth.resignFirstResponder()
    }

    @IBAction func okTapped(sender: AnyObject) {
        yearOfBirth.resignFirstResponder();
        if let year = Int(yearOfBirth.text!) {
            var zodiacImageNum = (year - offset) % 12
            zodiacImageNum = zodiacImageNum == 0 ? 12 : zodiacImageNum;
            zodiacImg.image = UIImage(named: String(zodiacImageNum))
        } else {
//            notify the user
        }

    }
}
 
